<template>
  <div class="mod-user">
    <!-- <el-card>
      <el-form
        :inline="true"
        :model="dataForm"
        @keyup.enter.native="getDataList()"
      >
        <el-form-item>
          <el-input
            v-model="dataForm.userName"
            placeholder="用户名"
            clearable
          ></el-input>
        </el-form-item>
        <el-form-item>
          <el-button @click="getDataList()">查询</el-button>
        </el-form-item>
      </el-form>
    </el-card> -->
    <el-card style="margin-top: 20px">
      业务场景：{{ paramsObj.scene }}
      <el-table
        :data="dataList"
        border
        style="width: 100%; margin-top: 10px"
        v-loading="loading"
        element-loading-text="拼命加载中"
        element-loading-spinner="el-icon-loading"
        element-loading-background="rgba(12,42,98, 0.9)"
      >
        <!-- <el-table-column
          type="selection"
          header-align="center"
          align="center"
          width="50"
        >
        </el-table-column> -->
        <el-table-column
          prop="sceneName"
          header-align="center"
          align="center"
          label="场景名称"
          width="330"
        >
        </el-table-column>
        <el-table-column
          prop="manufactorSystem"
          header-align="center"
          align="center"
          label="调用系统"
          width="250"
        >
        </el-table-column>
        <el-table-column
          prop="invokeCount"
          header-align="center"
          align="center"
          label="调用次数"
        >
        </el-table-column>
        <el-table-column
          prop="sendCount"
          header-align="center"
          align="center"
          label="推送人次"
        >
        </el-table-column>
        <el-table-column
          prop="shortCount"
          header-align="center"
          align="center"
          label="短信推送人次"
        >
        </el-table-column>
        <el-table-column
          prop="aiCount"
          header-align="center"
          align="center"
          label="外呼推送人次"
        >
        </el-table-column>
        <el-table-column
          prop="responseCount"
          header-align="center"
          align="center"
          label="响应人次"
        >
        </el-table-column>
        <el-table-column
          header-align="center"
          align="center"
          width="150"
          label="操作"
        >
          <template slot-scope="scope">
            <el-button type="text" size="small" @click="handleSearch(scope.row)"
              >预览</el-button
            >
          </template>
        </el-table-column>
      </el-table>
      <el-pagination
        @size-change="sizeChangeHandle"
        @current-change="currentChangeHandle"
        :current-page="pageIndex"
        :page-sizes="[10, 20, 50, 100]"
        :page-size="pageSize"
        :total="totalPage"
        layout="total, sizes, prev, pager, next, jumper"
      >
      </el-pagination>
    </el-card>
    <!-- 预览弹框 -->
    <el-dialog
      :title="title"
      :visible.sync="dialogSearchImg"
      width="55%"
      class="home_new_dialog"
    >
      <!-- <div style="margin: auto; width: 50rem; margin-bottom: 10px">
        <span>{{ title }}</span>
      </div> -->
      <div style="text-align: center">
        <img v-if="imgUrl" :src="imgUrl" alt="" />
        <span v-else>暂无图片，等待更新</span>
      </div>
    </el-dialog>
  </div>
</template>

<script>
export default {
  data() {
    return {
      loading: true,
      dataForm: {
        userName: "",
      },
      dataList: [],
      pageIndex: 1,
      pageSize: 10,
      totalPage: 0,
      dataListSelections: [],
      addOrUpdateVisible: false,
      dialogSearchImg: false,
      title: null,
      imgUrl: null,
      paramsObj: {
        scene: "",
      },
      timeValue: null,
    };
  },
  activated() {
    let paramsObj = this.$route.params.obj;
    let timeValue = this.$route.params.timeValue;
    console.log("paramsObj==", paramsObj);
    console.log("timeValue==", timeValue);
    if (paramsObj) {
      this.paramsObj = paramsObj;
      this.timeValue = timeValue;
      console.log("this.paramsObj=", this.paramsObj);
      console.log("this.paramsObj=", this.paramsObj.scene);
      this.getDataList();
    }
  },
  methods: {
    // 获取数据列表
    getDataList() {
      this.loading = true;
      this.$http({
        url: this.$http.adornUrl("/CcpcpHomePage/getCpcpHomePagePreviewList"),
        method: "get",
        params: this.$http.adornParams({
          pageNum: this.pageIndex,
          pageSize: this.pageSize,
          scene: this.paramsObj.scene,
          timeValue: this.timeValue,
          flag: 1, //1表示 业务场景推送预览 - 查看详情数据
        }),
      }).then(({ data }) => {
        if (data && data.code === 0) {
          console.log("-------------", data);
          this.dataList = data.data.records;
          this.totalPage = data.data.total;
          this.loading = false;
        } else {
          this.$message.error(res.data.msg);
          this.dataList = [];
          this.totalPage = 0;
        }
      });
    },
    // 每页数
    sizeChangeHandle(val) {
      this.pageSize = val;
      this.pageIndex = 1;
      this.getDataList();
    },
    // 当前页
    currentChangeHandle(val) {
      this.pageIndex = val;
      this.getDataList();
    },
    //预览
    handleSearch(obj) {
      // console.log("obj---",obj);
      console.log("obj---", obj.sceneName);
      // this.$message.info("暂无图片，等待更新")
      this.getImg(obj.sceneName);
    },
    //预览图片接口
    getImg(sceneName) {
      this.$http({
        url: this.$http.adornUrl("CcpcpHomePage/selectImgUrl"),
        method: "get",
        params: this.$http.adornParams({
          sceneName: sceneName,
        }),
      }).then(({ data }) => {
        if (data && data.code === 0) {
          console.log("-------------", data);
          // console.log("-------------", data.data.imgUrl);
          // if (data.data) {
          //   this.dialogSearchImg = true;
          //   this.imgUrl = data.data.imgUrl;
          //   this.title = data.data.sceneName;
          // }
          if (data.data != null) {
            this.dialogSearchImg = true;
            this.imgUrl = data.data.imgUrl;
            this.title = data.data.sceneName;
          } else {
            this.dialogSearchImg = true;
            this.imgUrl = "";
            this.title = "";
          }
        } else {
          this.$message.error(res.data.msg);
          this.dialogSearchImg = false;
          this.imgUrl = "";
          this.title = "";
        }
      });
    },
    // 多选
    // selectionChangeHandle(val) {
    //   this.dataListSelections = val;
    // },
    // 新增 / 修改
    // addOrUpdateHandle(id) {
    //   this.addOrUpdateVisible = true;
    //   this.$nextTick(() => {
    //     this.$refs.addOrUpdate.init(id);
    //   });
    // },
  },
};
</script>

